#version 120 
#extension GL_EXT_geometry_shader4 : enable

varying in vec3 normal[1];

//varying in vec3 eye[1];

varying out vec4 position;

varying out float dis;
	
varying out vec3 onor;
		
varying out vec3 originalPos;

uniform vec3 eye;

varying out vec4 gl_TexCoord[3];

void main(void)
{
	vec4 u=vec4(0,0,0,1);
	vec4 v=vec4(0,0,0,1);
	
	if(normal[0].x==0 && normal[0].y==0)
	{
		u.xyz=vec3(0,1,0);
		u.w=1;
	}
	else
	{
		u.x=-normal[0].y;
		u.y=normal[0].x;
		u.z=0.0;
	}

	u.xyz=normalize(u.xyz);
	u.w=0;
	v.xyz=normalize(cross(u.xyz,normal[0]));
	v.w=0;
	
	gl_TexCoord[0]=gl_TexCoordIn[0][0];
	gl_TexCoord[1]=gl_TexCoordIn[0][1];
	
	originalPos=gl_PositionIn[0].xyz;
	
	position=gl_PositionIn[0]+u*0.8;
	
	dis=length(position.xyz-eye);
	gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix*position;
	gl_TexCoord[2]=vec4(0.0,0.0,0.0,0.0);
	onor=normal[0];
	
	EmitVertex();
			
	position =gl_PositionIn[0]+v*0.8;
	dis=length(position.xyz-eye);
	gl_Position=gl_ProjectionMatrix * gl_ModelViewMatrix*position;
	gl_TexCoord[2]=vec4(0.0,1.0,0.0,0.0);
	onor=normal[0];
	EmitVertex();
		
	u.xyz=-u.xyz;
	v.xyz=-v.xyz;
	position=gl_PositionIn[0]+v*0.8;	

	dis=length(position.xyz-eye);
	gl_Position=gl_ProjectionMatrix * gl_ModelViewMatrix*position;
	gl_TexCoord[2]=vec4(1.0,0.0,0.0,0.0);
	onor=normal[0];
	EmitVertex();
	
	position=gl_PositionIn[0]+u*0.8;

	dis=length(position.xyz-eye);
	gl_Position=gl_ProjectionMatrix * gl_ModelViewMatrix*position;
	gl_TexCoord[2]=vec4(1.0,1.0,0.0,0.0);
	onor=normal[0];
	EmitVertex();
	
		
	EndPrimitive();	
	
	/////////////////////////////////////////////////////////////
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
